/**
 * 2号烧杯
 */
Beaker2 = Widget.extend({
	ctor:function(){
		this._super();
		this.initBeaker();
		this.setTag(TAG_BUNSEN2);
	},
	initBeaker:function(){			
		this.body = new Button(this, 10, TAG_BEAKER2, "#beaker/beaker.png", this.callback);
		this.body.setScale(1.3);

		var line = new cc.Sprite("#beaker_line.png");
		line.setOpacity(0);
		line.setPosition(31,7);
		line.setScale(1, 0.5);
		this.body.addChild(line, 5, TAG_BEAKER2_LINE);

		var nameLabel = new cc.LabelTTF("②", gg.fontName, 20);
		nameLabel.setColor(cc.color(0,0,0));
		nameLabel.setPosition(this.body.width * 0.5, 60);
		this.body.addChild(nameLabel);
		
		var salt = new cc.Sprite("#deposit1.png");
		salt.setOpacity(0);
		salt.setPosition(40, 73);
		this.body.addChild(salt,5,TAG_SALT);

		var hand = new Button(this, 9, TAG_RIGHT, "#hand_right.png", this.callback);
		hand.setPosition(cc.p(30,-45));
//		hand.setScale(0.7);
		hand.setVisible(false);
		var part = new Button(this, 11, TAG_RIGHT_PART, "#hand_part.png", this.callback);
		part.setPosition(cc.p(30,-45));
//		part.setScale(0.7);
		part.setVisible(false);
		
		this.callNext = cc.callFunc(function(){
			gg.flow.next();
		}, this);
		this.callNext.retain();
	},
	
	filter:/**
	 *过滤
	 **/
		function(pos) {
		var move=cc.moveTo(0.6,pos);
		var rot=cc.rotateTo(0.6, -55);
		var move1=cc.moveTo(0.6, cc.p(pos.x-7,pos.y));
		var rot1=cc.rotateTo(0.6, -80);
		var rot2=cc.rotateTo(0.6, -95);
		var spa=cc.spawn(move1,rot1);
		var rot3=cc.rotateTo(0.6, 0);
		var seq=cc.sequence(move,cc.callFunc(function() {
			var line = this.getChildByTag(TAG_BEAKER2).getChildByTag(TAG_BEAKER2_LINE);

			var moveto=cc.moveTo(0.6,cc.p(28,39));
			var rotate=cc.rotateTo(0.6, 55);
			var scale=cc.scaleTo(0.6, 1.4, 0.5);
			var spawn=cc.spawn(moveto,rotate,scale);


			var moveto1=cc.moveTo(0.8,cc.p(14,39))
			var scale1=cc.scaleTo(0.8, 1.4,0.4);
			var rotate1=cc.rotateTo(0.8, 80);
			var spawn1=cc.spawn(moveto1,scale1,rotate1);

			var moveto2=cc.moveTo(0.8,cc.p(8,39))
			var scale2=cc.scaleTo(0.8, 1.4,0.2);
			var rotate2=cc.rotateTo(0.8, 87);
			var spawn2=cc.spawn(moveto2,rotate2,scale2);

			var moveto3=cc.moveTo(0.8,cc.p(8,72))
			var scale3=cc.scaleTo(0.8, 0.1,0.1);
			var spawn3=cc.spawn(moveto3,scale3);

			var seq1=cc.sequence(spawn,spawn1,spawn2,spawn3);
			line.runAction(seq1);
		}, this),rot,cc.callFunc(function() {
//			this.schedule(this.getParent().loadFlow1, 0.1, 50, 2.5);
//			this.schedule(this.getParent().loadFlow2, 0.1, 50, 2.8);
			var salt=this.getChildByTag(TAG_BEAKER2).getChildByTag(TAG_SALT);
			var sca1=cc.scaleTo(0.6,1,1 );
			var	mov1=cc.moveTo(0.6,cc.p(20,22));
			var spa1=cc.spawn(sca1,mov1);

			var sca2=cc.scaleTo(0.6, 0, 0.2);
			var fad2=cc.fadeOut(0.6);
			var spa2=cc.spawn(sca2,fad2);
			var seq=cc.sequence(spa1,spa2,cc.callFunc(function() {
				salt.removeFromParent();
			}, this));
			salt.runAction(seq);
		}, this),spa,rot2,cc.delayTime(2),rot3,cc.callFunc(function() {				
			var rod=this.getParent().getChildByTag(TAG_DRAINAGE);
			rod.removeFromParent();
			this.removeFromParent();
		}, this),this.callNext);
		this.runAction(seq);
	},
	callback:function(p){
		var action=gg.flow.flow.action;
		var hand=this.getChildByTag(TAG_RIGHT);
		var part=this.getChildByTag(TAG_RIGHT_PART);

		switch(p.getTag()){
		case TAG_BEAKER2:
			if(action==ACTION_DO1){				
				hand.setVisible(true);
				part.setVisible(true);
				var move=cc.moveTo(0.6, cc.p(640,310));
				var seq=cc.sequence(move,cc.callFunc(function() {
					hand.setVisible(false);
					part.setVisible(false);
				}, this),this.callNext);
				this.runAction(seq);
			}else if(action==ACTION_DO2){
				hand.setVisible(true);
				part.setVisible(true);
				this.filter(cc.p(193,400));
				var line3=this.getParent().getChildByTag(TAG_BUNSEN3).getChildByTag(TAG_BEAKER3)
				.getChildByTag(TAG_BEAKER3_LINE);
				var seq=cc.sequence(cc.delayTime(1.6),cc.fadeIn(0),cc.moveTo(2,cc.p(31,40)));
				line3.runAction(seq);				
			}
			break;
		}
	},
	onExit:function(){
		this._super();
		this.callNext.release();
	}
});